package dao.impl;
import Utils.C3P0Utils;
import domain.User;
import dao.UserDao;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;


/**
 * @Author admin
 * @Date 2019/3/5 8:37
 */
public class UserDaoImpl implements UserDao {
    @Override
    public User login(String username, String password) {
        QueryRunner runner= new QueryRunner(C3P0Utils.getDataSource());
        String sql="SELECT * FROM USER WHERE username=? AND password=?";
        User query = null;
        try {
            query = runner.query(sql, new BeanHandler<User>(User.class), username, password);
        } catch (SQLException e) {


        }
        return query;

    }

    @Override
    public User register(String username, String email, String password) throws SQLException {
        QueryRunner runner= new QueryRunner(C3P0Utils.getDataSource());
        String sql="INSERT INTO USER (username,email,PASSWORD)VALUES(?,?,?)";
        runner.update(sql,new Object[]{});
        return null;
    }
}
